// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.reports.editor.design.models;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-2-20 qiang.zhang $
 * 
 */
public class DesignElementFactory {

    private static DesignElementFactory instance;

    /**
     * Qiang.Zhang.Adolf@gmail.com DesignElementFactory constructor comment.
     */
    private DesignElementFactory() {
    }

    /**
     * Getter for instance.
     * 
     * @return the instance
     */
    public static DesignElementFactory getInstance() {
        if (instance == null) {
            instance = new DesignElementFactory();
        }
        return instance;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "newTableDiagram".
     * 
     * @param newTable
     * @param colNum
     * @param rowNum
     * @return
     */
    public RepTableDiagram newTableDiagram(String newTable, int colNum, int rowNum) {
        RepTableDiagram diagram = new RepTableDiagram(newTable);
        colNum = colNum >= 0 ? colNum : 0;
        rowNum = rowNum >= 0 ? rowNum : 0;
        for (int i = 0; i < colNum; i++) {
            RepTableColumnDiagram columnDiagram = new RepTableColumnDiagram();
            diagram.addRepTableColumnDiagram(columnDiagram);
        }
        for (int i = 0; i < rowNum; i++) {
            RepTableRowDiagram rowDiagram = newRepTableRowDiagram(colNum);
            diagram.addRepTableRowDiagram(rowDiagram);
        }
        diagram.fixRepTableCellDiagram();
        return diagram;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "newRepTableRowDiagram".
     * 
     * @param colNum
     * @return
     */
    private RepTableRowDiagram newRepTableRowDiagram(int colNum) {
        RepTableRowDiagram rowDiagram = new RepTableRowDiagram();
        for (int j = 0; j < colNum; j++) {
            RepTableCellDiagram cellDiagram = new RepTableCellDiagram();
            rowDiagram.addRepTableCells(cellDiagram);
        }
        return rowDiagram;
    }
}
